﻿Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices

Public Class SDK_Comercial
    Public Const kTokenSeparadorSACICOM = "¬"

    Public Const kHandleESC = 18
    Public gPresionoESC As Boolean
    Public Const sNull As String = ""

    Public Structure TDBERROR
        Dim nErrorSeverity As Integer
        Dim nErrorCode As Integer
        Dim nSubErrorCode As Integer
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=120)> Dim szErrorMsg As Byte()
    End Structure
    Public Structure TRECT
        Dim Left As Long
        Dim Top As Long
        Dim Right As Long
        Dim bottom As Long
    End Structure

    Public Const kNinguno = 0
    Public Const kClientes = 1
    Public Const kProveedores = 2
    Public Const kProductos = 3
    Public Const kAgentes = 4
    Public Const kAlmacenes = 5
    Public Const kClientesProveedores = 6
    Public Const kDocumentos = 7
    Public Const kConceptos = 8
    Public Const kDirecciones = 9

    Public Const kBusquedaPorConcepto = 1
    Public Const kBusquedaPorDoctoDe = 2

    '***********************************************************************************************************************************************************
    'Objetos nuevo metodo de accso 24/04/13 JDV
    '***********************************************************************************************************************************************************
   

    'Public gGuidCom As String
    'Public gGuidTablas As String

    Dim gListaEmpresas, gListaRutasEmpresas, gListaIdsEmpresas, gListaRespaldosEmpresas As String


    Public Declare Function dbLogin Lib "DBFWIN32.DLL" Alias "dbLogIn" (ByVal UserName As String, ByVal FilePath As String) As Long
    Public Declare Sub dbLogOut Lib "DBFWIN32.DLL" (ByVal hDbc As Long)
    Public Declare Function dbCmdExec Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal CmdStr As String) As Long
    Public Declare Function dbFieldChar Lib "DBFWIN32.DLL" Alias "dbFieldCharBDE" (ByVal hDbc As Long, ByVal FileName As String, ByVal nField As Long, ByVal Buffer As String, ByVal nlen As Integer) As Long
    Public Declare Function dbFieldMemo Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal FileName As String, ByVal nField As Long, ByVal Buffer As String, ByVal nlen As Long) As Long
    Public Declare Function dbFieldInt Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal FileName As String, ByVal nField As Long, lpInt As Integer) As Long
    Public Declare Function dbFieldLong Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal FileName As String, ByVal nField As Long, lpLong As Long) As Long
    Public Declare Function dbFieldDouble Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal FileName As String, ByVal nField As Long, lpDouble As Double) As Long
    Public Declare Function dbGetNoLock Lib "DBFWIN32.DLL" Alias "dbGetNoLockBDE" (ByVal hDbc As Long, ByVal FileName As String, ByVal TagName As String, ByVal Key As String) As Long
    Public Declare Function dbGetTopNoLock Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal FileName As String, ByVal TagName As String) As Long
    Public Declare Function dbGetBottomNoLock Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal FileName As String, ByVal TagName As String) As Long
    Public Declare Function dbGetNextNoLock Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal FileName As String, ByVal TagName As String, ByVal PrevKey As String) As Long
    Public Declare Function dbKey Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal FileName As String, ByVal TagName As String, ByVal Key As String, ByVal nlen As Integer) As Long
    Public Declare Function dbKeySet Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal FileName As String, ByVal TagName As String, ByVal Key As String, ByVal nlen As Integer) As Long
    Public Declare Sub dbResult Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByRef dbError As TDBERROR)
    Public Declare Function dbSkip Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal FileName As String, ByVal TagName As String, ByVal DIRECCION As Long) As Long
    Public Declare Function dbTagSelect Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal FileName As String, ByVal TagName As String) As Long
    ' Funciones de obtención de valores de los campos por su nombre
    Public Declare Function dbFieldNameChar Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal FileName As String, ByVal FieldName As String, ByVal Buffer As String, ByVal nlen As Integer) As Long
    Public Declare Function dbFieldNameLong Lib "DBFWIN32.DLL" (ByVal hDbc As Long, ByVal FileName As String, ByVal FieldName As String, ByVal lpLong As Long) As Long

    Public Const kLongNombre = 60 + 1
    Public Const kLongCodigo = 30 + 1
    Public Const kLongSerie = 11 + 1
    Public Const kLongFecha = 23 + 1
    Public Const kLongReferencia = 20 + 1
    Public Const kLongDescripcion = 60 + 1
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=4)> _
     Public Structure tRegDocumento
        Dim aFolio As Double
        Dim aNumMoneda As Long
        Dim aTipoCambio As Double
        Dim aImporte As Double
        Dim aDescuentoDoc1 As Double
        Dim aDescuentoDoc2 As Double
        Dim aSistemaOrigen As Long
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=kLongCodigo)> Dim aCodConcepto As Byte()
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=kLongSerie)> Dim aSerie As Byte()
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=kLongFecha)> Dim aFecha As Byte()
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=kLongCodigo)> Dim aCodigoCteProv As Byte()
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=kLongCodigo)> Dim aCodigoAgente As Byte()
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=kLongReferencia)> Dim aReferencia As Byte()
        Dim aAfecta As Long
    End Structure
    Public Structure tRegLlaveDoc
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=kLongCodigo)> Dim aCodConcepto As Byte()
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=kLongSerie)> Dim aSerie As Byte()
        Dim aFolio As Double
    End Structure

    <DllImport("MGW_SDK.DLL")> _
    Public Shared Function fSetNombrePAQ(aNombrePAQ As [String]) As Integer
    End Function

    Public Declare Function fInicializaSDK Lib "MGW_SDK.DLL" () As Long
    Public Declare Sub fNoApagarMotorBD Lib "MGW_SDK.DLL" ()

    <DllImport("mgw_sdk.dll")> _
    Public Shared Sub fTerminaSDK()
    End Sub

    '<DllImport("mgw_sdk.dll")> _
    'Public Shared Sub fError(NumeroError As Integer, Mensaje As String, Longitud As Integer)
    'End Sub
    Public Declare Sub fError Lib "MGW_SDK.DLL" (ByVal aNumError As Integer, ByVal aError As String, ByVal aLen As Integer)
    Public Declare Sub fSetModoImportacion Lib "MGW_SDK.DLL" (aModoImportacion As Long)

    <DllImport("mgw_sdk.dll")> _
    Public Shared Function fAbreEmpresa(Directorio As String) As Integer
    End Function
    

    <DllImport("mgw_sdk.dll")> _
    Public Shared Sub fCierraEmpresa()
    End Sub

    Declare Function fInsertarDocumento Lib "MGW_SDK.DLL" () As Long
    Declare Function fGuardaDocumento Lib "MGW_SDK.DLL" () As Long
    Declare Function fSetDatoDocumento Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String) As Long
    Declare Function fLeeDatoDocumento Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String, ByVal aLongitud As Long) As Long
    Declare Function fBorraDocumento Lib "MGW_SDK.DLL" () As Long

    Declare Function fInsertarMovimiento Lib "MGW_SDK.DLL" () As Long
    Declare Function fGuardaMovimiento Lib "MGW_SDK.DLL" () As Long
    Declare Function fSetDatoMovimiento Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String) As Long
    Declare Function fCancelaCambiosMovimiento Lib "MGW_SDK.DLL" () As Long
    Declare Function fCancelarModificacionDocumento Lib "MGW_SDK.DLL" () As Long

    Declare Function fAltaDocumentoCargoAbono Lib "MGW_SDK.DLL" (aDocumento As tRegDocumento) As Long
    Declare Function fAfectaDocto Lib "MGW_SDK.DLL" (aDocumento As tRegLlaveDoc, ByVal aAfecta As Long) As Long
    Declare Function fSaldarDocumento Lib "MGW_SDK" (astDoctoAPagar As tRegLlaveDoc, astDoctoPago As tRegLlaveDoc, ByVal aImporte As Double, ByVal aIdMoneda As Long, ByVal aFecha As String) As Long
    Declare Function fBuscaDocumento Lib "MGW_SDK" (aDocumento As tRegLlaveDoc) As Long
    Declare Function fSiguienteFolio Lib "MGW_SDK.DLL" (ByVal aCodigoConcepto As String, ByVal aSerie As String, aFolio As Double) As Long
    'N.D.- 7111
    Declare Function fBuscarIdDocumento Lib "MGW_SDK.DLL" (ByVal aIdDocumento As Long) As Long

    'Conceptos
    'N.D.  7111
    Declare Function fBuscaConceptoDocto Lib "MGW_SDK.DLL" (ByVal aCodigoConcepto As String) As Long
    Declare Function fLeeDatoConceptoDocto Lib "MGW_SDK.DLL" (ByVal aNombreCampo As String, ByVal aValor As String, ByVal aLongitus As Long) As Long

    ' 26/09/2005 LAP S.C.01 Inicio
    ' Exportación de Catalogos
    ' Clientes / Proveedores
    Declare Function fBuscaCteProv Lib "MGW_SDK.DLL" (ByVal aCodCteProv As String) As Long
    Declare Function fInsertaCteProv Lib "MGW_SDK.DLL" () As Long
    Declare Function fSetDatoCteProv Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String) As Long
    Declare Function fLeeDatoCteProv Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String, ByVal aLen As Long) As Long
    Declare Function fGuardaCteProv Lib "MGW_SDK.DLL" () As Long
    Declare Function fCancelarModificacionCteProv Lib "MGW_SDK.DLL" () As Long
    Declare Function fEditaCteProv Lib "MGW_SDK.DLL" () As Long

    ' Productos
    Declare Function fBuscaProducto Lib "MGW_SDK.DLL" (ByVal aCodigoProducto As String) As Long
    Declare Function fInsertaProducto Lib "MGW_SDK.DLL" () As Long
    Declare Function fBorraProducto Lib "MGW_SDK.DLL" () As Long
    Declare Function fEditaProducto Lib "MGW_SDK.DLL" () As Long
    Declare Function fSetDatoProducto Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String) As Long
    Declare Function fLeeDatoProducto Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String, ByVal aLen As Long) As Long
    Declare Function fGuardaProducto Lib "MGW_SDK.DLL" () As Long
    Declare Function fCancelarModificacionProducto Lib "MGW_SDK.DLL" () As Long
    Declare Function fSetDescripcionProducto Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String) As Long

    ' Agentes
    Declare Function fBuscaAgente Lib "MGW_SDK.DLL" (ByVal aCodProducto As String) As Long
    Declare Function fInsertaAgente Lib "MGW_SDK.DLL" () As Long
    Declare Function fSetDatoAgente Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String) As Long
    Declare Function fLeeDatoAgente Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String, ByVal aLen As Long) As Long
    Declare Function fGuardaAgente Lib "MGW_SDK.DLL" () As Long
    Declare Function fCancelarModificacionAgente Lib "MGW_SDK.DLL" () As Long
    Declare Function fEditaAgente Lib "MGW_SDK.DLL" () As Long

    ' Almacenes
    Declare Function fBuscaAlmacen Lib "MGW_SDK.DLL" (ByVal aCodProducto As String) As Long
    Declare Function fInsertaAlmacen Lib "MGW_SDK.DLL" () As Long
    Declare Function fSetDatoAlmacen Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String) As Long
    Declare Function fLeeDatoAlmacen Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String, ByVal aLen As Long) As Long
    Declare Function fGuardaAlmacen Lib "MGW_SDK.DLL" () As Long
    Declare Function fCancelarModificacionAlmacen Lib "MGW_SDK.DLL" () As Long
    Declare Function fEditaAlmacen Lib "MGW_SDK.DLL" () As Long ' 02/04/2007 AMG ND 4550
    ' 26/09/2005 LAP S.C.01 Fin

    ' Direcciones
    Declare Function fBuscaDireccionCteProv Lib "MGW_SDK.DLL" (ByVal aCodigoCliente As String, ByVal aTipoDireccion As Byte) As Long
    Declare Function fInsertaDireccion Lib "MGW_SDK.DLL" () As Long
    Declare Function fSetDatoDireccion Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String) As Long
    Declare Function fLeeDatoDireccion Lib "MGW_SDK.DLL" (ByVal aCampo As String, ByVal aValor As String, ByVal aLen As Long) As Long
    Declare Function fGuardaDireccion Lib "MGW_SDK.DLL" () As Long
    Declare Function fCancelarModificacionDireccion Lib "MGW_SDK.DLL" () As Long
    Declare Function fEditaDireccion Lib "MGW_SDK.DLL" () As Long

    '**********************************************************
    'API's de Windows
    '**********************************************************
    Public Declare Function GetPrivateProfileString% Lib "KERNEL32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName$, ByVal lpKeyName As Int32(), ByVal lpDefault$, ByVal lpReturnedString$, ByVal nSize%, ByVal lpFileName$)
    Public Declare Function GetPrivateProfileInt% Lib "KERNEL32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName$, ByVal lpKeyName$, ByVal nDefault%, ByVal lpFileName$)
    Public Declare Function lstrcat& Lib "KERNEL32" (ByVal lpString1 As Int32(), ByVal lpString2 As Int32())
    Public Declare Function lstrlen% Lib "KERNEL32" (ByVal lpString As Int32())
    Public Declare Function GetEnvironmentVariable% Lib "KERNEL32" Alias "GetEnvironmentVariableA" (ByVal lpApplicationName$, ByVal lpKeyName$, ByVal nDefault%)
    Public Declare Function SetEnvironmentVariable% Lib "KERNEL32" Alias "SetEnvironmentVariableA" (ByVal lpApplicationName$, ByVal lpKeyName$)

    ' API's de Windows para accesos al Registry DB
    Public Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
    Public Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByVal szData As String, ByRef lpcbData As Long) As Long

    <DllImport("KERNEL32")> _
    Public Shared Function SetCurrentDirectory(pPtrDirActual As String) As Integer
    End Function

    ' Constantes de llaves del Registry
    Public Const HKEY_LOCAL_MACHINE = &H80000002

    '**********************************************************
    'Constantes importantes de la aplicacion
    '**********************************************************
    Public Const REN_INICIAL = 4 'renglón de inicio del listado en la hoja Exel

    '**********************************************************
    'Constantes de la base de datos
    '**********************************************************
    'Archivos

    'Empresas , directorio global, ubicaciones de las empresas
    Public Const GEMPRESAS = "Mgw00001"
    Public Const IxGEMPRESAS = "PrimaryKey"
    Public Const IxNOMEMPRESA = "cNombreE01"

    'Datos de la empresa
    Public Const lEmpresa = "Mgw10000"
    Public Const IxLEMPRESA = "PrimaryKey"
    Public Const EMPRESA_NOMBRE = 2
    Public Const EMPRESA_EJERCICIO = 4
    Public Const EMPRESA_CONTPAQI = 36
    Public Const EMPRESA_NUM_IVA = 107
    Public Const EMPRESA_VERSION = 108
    Public Const EMPRESA_PRODPOS1 = 110
    Public Const EMPRESA_PRODPOS2 = 111
    Public Const EMPRESA_PRODPOS3 = 112
    Public Const EMPRESA_PRODPOS4 = 113
    Public Const EMPRESA_PRODPOS5 = 114

    'Tabla de Productos
    Public Const PRODUCTOS = "Mgw10005"
    Public Const IxPRODUCTOS = "iCodigoT01" 'cCodigoProducto + cTipoProducto
    Public Const IxIDPRODUCTOS = "PrimaryKey"
    Public Const PROD_ID = 1
    Public Const PROD_CODIGO = 2
    Public Const PROD_DESCRIPCION = 3
    Public Const PROD_CONTROL = 6
    Public Const PROD_TIPO = 4
    Public Const PROD_COSTO = 13
    Public Const PROD_METODOCOSTEO = 9


    'Tabla de Lista de Precios de Compra
    Public Const LISTA_PRECIOS_COMPRA = "MGW10014"
    Public Const IxPRODUCTOPROVEEDOR = "PrimaryKey"
    Public Const LISTAPREC_PRECIOCOMPRA = 3
    Public Const LISTAPREC_IDMONEDA = 4
    Public Const LISTAPREC_CODIGOALTERNO = 5
    Public Const LISTAPREC_IDUNIDAD = 6


    'Tabla de Ubicaciones (hva)
    Public Const UBICACIONES = "Mgw10016"
    ' 17/02/2003 LAP SoluPAQ Utilización de IxUBICACIONES para referenciar el índice primario
    Public Const IxUBICACIONES = "PrimaryKey"

    ' Tabla de detalle de productos
    Public Const DETALLE_PROD = "Mgw10004"
    Public Const IxIDDETALLE = "PrimaryKey"
    Public Const IxDETALLE = "iProdPad01"

    Public Const DETALLE_ID = 1
    Public Const DETALLE_TIPO = 2
    Public Const DETALLE_PADRE = 3

    'Foto del producto
    Public Const FOTO = "Img10001"
    ' 17/02/2003 LAP SoluPAQ Utilización de IxFOTO para referenciar el índice primario
    Public Const IxFOTO = "PrimaryKey"

    'Tabla de Conceptos
    Public Const CONCEPTOS = "Mgw10006"
    Public Const IxIDCONCEPTOS = "PrimaryKey"
    Public Const IxCODCONCEPTO = "cCodigoC01"
    Public Const IxDOCTOMODELO = "cIdDocum01"
    Public Const IxCONCEPTO_NOMBRE = "iNombreN01"
    Public Const CONCEPTOS_ID = 1
    Public Const CONCEPTOS_CODIGO = 2
    Public Const CONCEPTOS_DESCRIPCION = 3
    Public Const CONCEPTOS_DOCTODE = 4

    'Tabla de Documentos Modelo 05/03/2003 LAP SoluPAQ
    Public Const DOCTOSDE = "Mgw10007"
    Public Const IxDOCTOSDE = "PrimaryKey"
    Public Const IxDESCRIPCION = "CDESCRIP01"
    Public Const DOCTOSDE_DESCRIP = 2
    ' 13/02/2004 ND 1685 LAP
    Public Const DOCTOSDE_USACTE = 8
    Public Const DOCTOSDE_USAPROV = 9
    Public Const DOCTOSDE_NATURALEZA = 3
    Public Const DOCTOSDE_AFECTAEXISTENCIA = 4

    'Tabla de Almacenes
    Public Const ALMACEN = "Mgw10003"
    Public Const IxALMACEN = "PrimaryKey"
    Public Const IxCODALMACEN = "cCodigoA01"

    'Tabla de Movimientos
    Public Const MOVIMIENTOS = "Mgw10010"
    Public Const IxIDMOVTOS = "PrimaryKey"
    Public Const IxMOVIMIENTOS = "iDoctoNu01"
    Public Const IxMOVPRODUCTO = "iProduct02"
    Public Const IxMOVPRODALM = "iProduct04"
    Public Const IxMOVPRODFECHA = "iProduct03"
    Public Const IxMOVOWNER = "iMovtoOw01"
    Public Const IxMOVORIGEN = "cIdMovto01"

    'Tabla de Clientes y Provedores
    Public Const CLIENTES = "Mgw10002"
    Public Const IxCLIENTES = "PrimaryKey"
    Public Const IxCODCLIENTES = "iCodigoT01"   ' cCodigoCliente + cTipoCliente
    Public Const TIPO_CLIPRO = 20
    Public Const CLIENTES_IDMONEDA = 9
    Public Const CLIENTES_CODIGO = 2
    Public Const CLIENTES_RAZONSOCIAL = 3
    Public Const CLIENTES_RFC = 5
    Public Const CLIENTES_ID = 1

    'Tabla de Monedas
    Public Const MONEDAS = "Mgw10034"
    Public Const IxMONEDAS = "PrimaryKey"
    Public Const IxMONEDAS_NOMBRE = "CNOMBREM01"
    Public Const MONEDAS_ID = 1
    Public Const MONEDAS_NOMBRE = 2
    Public Const MONEDAS_DESCRIPCION = 7
    Public Const MONEDAS_PLURAL = 5
    Public Const MONEDAS_SINGULAR = 6

    Public Const MONEDAS_TIPOCAMBIO = "Mgw10035"
    Public Const IxMONEDAA = "iMonedaF02"
    Public Const IxMONEDAD = "iMonedaF01"
    Public Const TIPOCAMBIO_IDMONEDA = 2
    Public Const TIPOCAMBIO_FECHA = 3
    Public Const TIPOCAMBIO_IMPORTE = 4

    Public Const CATACLASIF = "Mgw10019"
    ' 17/02/2003 LAP SoluPAQ Utilización de IxCATACLASIF para referenciar el índice primario
    Public Const IxCATACLASIF = "PrimaryKey"

    'Tabla de Clasificaciones
    Public Const CLASIFICACIONES = "Mgw10020"
    Public Const IxCLASIFICACIONES = "PrimaryKey"
    Public Const IxCODIGOCLAS = "icCodigo01"
    ' 02/04/2003 LAP SoluPAQ Utilización del indice iClasifv01 ya que es el mismo que utiliza
    ' AdminPAQ. Esto ya que si el nombre del valor de la descripción contenia acentos
    Public Const IxCLASIFVALOR = "iClasifv01" '"iClasifi01"

    Public Const campo = 0

    'Tabla de Agentes
    Public Const AGENTES = "Mgw10001"
    Public Const IxAGENTES = "PrimaryKey"
    Public Const IxCODAGENTES = "iCodigoT01"

    'Tabla de Periodos y Ejercicios
    Public Const EJERCICIO = "Mgw10031"
    Public Const IxEJERCICIO = "PrimaryKey"
    Public Const PERIODOINICIAL = 3
    Public Const fechaFinal = 15
    Public Const EJERCICIO_ACTUAL = 16

    'Tabla de Costos históricos
    Public Const COSTOS = "Mgw10017"
    Public Const IxCOSTOS = "iProdAlm01"
    Public Const COSTOS_IDPRODUCTO = 2
    Public Const COSTOS_IDALMACEN = 3
    Public Const COSTOS_FECHA = 4
    Public Const COSTOS_PROMEDIO = 5
    Public Const COSTOS_ULTIMO = 6

    'Tabla de Acumulados
    Public Const ACUMULADOS = "Mgw10018"
    Public Const IxACUMULADOS = "iAcumImp01"
    Public Const ACUM_TIPOACUMULADO = 2
    Public Const ACUM_OWNER1 = 3
    Public Const ACUM_OWNER2 = 4
    Public Const ACUM_IMPORTEMODELO = 5
    Public Const ACUM_MONEDA = 8
    Public Const ACUM_EJERCICIO = 6
    Public Const ACUM_IMPORTEINICIAL = 7
    Public Const ACUM_IMPORTEPERIODO1 = 9

    'Tabla de unidad de medida y peso
    Public Const Unidad = "Mgw10026"
    Public Const IxUNIDAD = "PrimaryKey"

    'Tabla de existencias
    Public Const EXISTENCIA = "Mgw10030"
    Public Const IxEXIALMACEN = "iProdEje02"
    Public Const IxEXIPRODUCTO = "iProdEje01"
    Public Const EXI_IDALMACEN = 2
    Public Const EXI_IDPRODUCTO = 3
    Public Const EXI_IDEJERCICIO = 4
    Public Const EXI_TIPO = 5
    Public Const EXI_ENTUNIINICIAL = 6
    Public Const EXI_SALUNIINICIAL = 7
    Public Const EXI_ENTCOSINICIAL = 8 '(7)
    Public Const EXI_SALCOSINICIAL = 9
    Public Const EXI_ENTUNI1 = 10 '(8)
    Public Const EXI_SALUNI1 = 22 '(20)
    Public Const EXI_ENTCOS1 = 34 '(32)
    Public Const EXI_SALCOS1 = 46

    ' 26/09/2005 LAP S.C.01 Inicio
    Public Const CARACTERISTICAS = "MGW10021"
    Public Const IxCARACTERISTICAS = "PrimaryKey"
    ' 26/09/2005 LAP S.C.01 Fin

    ' Tabla de valores de caracteristicas
    Public Const VALOR_CAR = "Mgw10022"
    Public Const IxPADRENEMO = "iPadreNemo"

    ' 17/02/2003 LAP SoluPAQ Utilización de IxIDVALOR_CAR para referenciar el índice primario
    Public Const IxIDVALOR_CAR = "PrimaryKey"
    Public Const IxVALOR_CAR = "cValorCa01"

    ' 01/11/2007 JAAM Tabla Prepoliza
    Public Const PREPOLIZA = "MGW10038"
    Public Const IxPREPOLPK = "PrimaryKey"
    Public Const IxPREPOLFECHA = "Fecha"
    Public Const IxPREPOLFECHATN = "iFechaTi01"
    Public Const IxPREPOLPERITN = "iEjePeri01"
    Public Const PREPOL_ID = 1
    Public Const PREPOL_ESTADO = 2
    Public Const PREPOL_EJERCICIO = 3
    Public Const PREPOL_PERIODO = 4
    Public Const PREPOL_TIPOPOL = 5
    Public Const PREPOL_NUMPOL = 6
    Public Const PREPOL_CONCEPTO = 9
    Public Const PREPOL_FECHA = 10
    Public Const PREPOL_CARGO = 11
    Public Const PREPOL_ABONO = 12
    Public Const PREPOL_DIARIO = 13

    ' 14/11/2007 JAAM Tabla Movimiento de Prepolizas
    Public Const MOV_PREPOLIZA = "MGW10039"
    Public Const IxMOVPREPOLPK = "PrimaryKey"
    Public Const IxPREPOLIZA1 = "iPrepoli01"
    Public Const IxPREPOLIZA2 = "iPrepoli02"
    Public Const ID_MOV_POLIZA = 2
    Public Const MPOL_EJERCICIO = 3
    Public Const MPOL_PERIODO = 4
    Public Const MPOL_TIPO_POL = 5
    Public Const MPOL_NUM_POL = 6
    Public Const MPOL_NUM_MOV = 7
    Public Const MPOL_CUENTA = 8
    Public Const MPOL_TIPO_MOV = 9
    Public Const MPOL_IMPORTE = 11

    ' Campos de la tabla de Empresas, global
    Public Const GEMPR_ID = 1
    Public Const GEMPR_NOMBRE = 2
    Public Const GEMPR_UBICACION = 3
    Public Const GEMPR_IMPUESTO = 106

    'Tabla de Documentos
    Public Const ASOCIA = "Mgw10009"
    Public Const IxABONO = "PrimaryKey"
    Public Const IxCARGO = "iDoctoCa01"
    Public Const ASOCIA_ABONO = 3
    Public Const ASOCIA_CARGO = 4
    Public Const ASOCIA_IDABONO = 1
    Public Const ASOCIA_IDCARGO = 2

    'Tabla de Documentos
    Public Const DOCTOS = "Mgw10008"
    Public Const IxDOCUMENTO = "PrimaryKey"
    Public Const IxDOCAGENTE = "iDocumen03"
    Public Const IxDOCCLIENTE = "iDocumen02"
    Public Const IxCLIENTEFECHA = "iCliente01"
    Public Const IxDOCFECHA = "iDoctoDe01"
    Public Const IxDOCORIGEN = "cIdDocum01" ' RDAT 21-Jun-02 Indice por Documento Origen
    Public Const IxDOCDEFECHASERIEFOL = "iDocumen01" ' RDAT 12-Sep-2002 Indice por DoumentoDe+Fecha+Serie+Folio
    ' 12/05/2003 LAP
    Public Const IxDOCCLIENTECONCEPTO = "iCliente02"  'cIdClien01+cIdConce01+cFecha+cSerieDo01+cFolio
    Public Const IxDOCAGENTEFECHA = "iAgenteF01"      'cIdAgente+cFecha+cSerieDo01+cFolio
    Public Const IxDOCCONCEPTO = "iConcept01"         'cIdConce01+cFecha+cSerieDo01+cFolio
    Public Const IxDOCCLIENTEAFEC = "iCliente03"  ' cIdClien01+cAfectado+cNatural01+cFechaVe01
    Public Const IxIDCONFOLIO = "ICONCEPT02" 'cIdConce01 + cFolio

    Public Const DOCTO_DIGITAL = "Mgw10045"
    Public Const IxCIDDOCTO = "cIdDocto"
    ' Tabla de Direcciones
    Public Const DIRECCION = "Mgw10011"
    Public Const IxDIRECCION = "iCatTipo01"
    Public Const DIRECCION_EMAIL = 14

    ' Campos de la tabla de Documentos
    Public Const DOCTO_ID = 1
    Public Const DOCTO_IDDOCTODE = 2
    Public Const DOCTO_IDCONCEPTODOCTO = 3 ' hva 16/12/2002
    Public Const DOCTO_SERIE = 4
    Public Const DOCTO_FOLIO = 5
    Public Const DOCTO_FECHA = 6
    Public Const DOCTO_AFECTADO = 24
    Public Const DOCTO_IMPRESO = 25
    Public Const DOCTO_CANCELADO = 26
    Public Const DOCTO_DEVUELTO = 27

    Public Const DOCTO_TIPOCAMBIO = 16
    Public Const DOCTO_IDAGENTE = 10
    Public Const DOCTO_IDCLIENTE = 7
    Public Const DOCTO_RAZONSOCIAL = 8
    Public Const DOCTO_NATURALEZA = 19
    Public Const DOCTO_MONEDA = 15
    Public Const DOCTO_DOCORIGEN = 20 ' RDAT 21-Jun-02 Documento Origen
    Public Const DOCTO_UNIDADES = 45
    Public Const DOCTO_REFERENCIA = 17

    ' Importe Base del Documento
    Public Const DOCTO_NETO = 31
    Public Const DOCTO_TOTAL = 43
    Public Const DOCTO_DESCUENTO = 37
    Public Const DOCTO_IMPORTEEXTRA1 = 57
    Public Const DOCTO_IMPORTEEXTRA2 = 58
    Public Const DOCTO_IMPORTEEXTRA3 = 59
    Public Const DOCTO_IMPORTEEXTRA4 = 60
    Public Const DOCTO_IMPUESTO1 = 32
    Public Const DOCTO_IMPUESTO2 = 33
    Public Const DOCTO_IMPUESTO3 = 34
    Public Const DOCTO_RETENCION1 = 35
    Public Const DOCTO_RETENCION2 = 36
    Public Const DOCTO_GASTO1 = 40
    Public Const DOCTO_GASTO2 = 41
    Public Const DOCTO_GASTO3 = 42
    Public Const DOCTO_PENDIENTE = 44
    Public Const DOCTO_UNIDPENDIENTE = 71 ' EPF 05-Jun-02 Unidades pendientes del documento

    ' Campos de la tabla de Movimientos
    Public Const MOVTO_IDMOVTO = 1
    Public Const MOVTO_IDDOCTO = 2
    Public Const MOVTO_NUMERO = 3
    Public Const MOVTO_FECHA = 44
    Public Const MOVTO_IDDOCTODE = 4
    Public Const MOVTO_IDPRODUCTO = 5
    Public Const MOVTO_ALMACEN = 6
    Public Const MOVTO_UNIDAD = 7
    Public Const MOVTO_UNIDADNC = 8
    Public Const MOVTO_CAPTURADA = 9
    Public Const MOVTO_PRECIO = 12
    Public Const MOVTO_COSTOCAPTURADO = 14
    Public Const MOVTO_COSTOESPECIFICO = 15
    Public Const MOVTO_NETO = 16
    Public Const MOVTO_IMPUESTO1 = 17
    Public Const MOVTO_PORCIMP1 = 18
    Public Const MOVTO_IMPUESTO2 = 19
    Public Const MOVTO_PORCIMP2 = 20
    Public Const MOVTO_IMPUESTO3 = 21
    Public Const MOVTO_PORCIMP3 = 22
    Public Const MOVTO_RETENCION1 = 23
    Public Const MOVTO_RETENCION2 = 25
    Public Const MOVTO_DESCUENTO1 = 27
    Public Const MOVTO_DESCUENTO2 = 29
    Public Const MOVTO_DESCUENTO3 = 31
    Public Const MOVTO_DESCUENTO4 = 33
    Public Const MOVTO_DESCUENTO5 = 35
    Public Const MOVTO_TOTAL = 37
    Public Const MOVTO_AFECTAINVENTARIO = 43
    Public Const MOVTO_AFECTASALDOS = 42
    Public Const MOVTO_EXISTENCIAS = 41
    Public Const MOVTO_OWNER = 46
    Public Const MOVTO_MOVTOORIGEN = 47 ' RDAT 21-Jun-02 Movimiento Origen
    Public Const MOVTO_PEND = 48 ' EPF 05-Jun-02 Unidades pendientes del movimiento
    Public Const MOVTO_PENDNC = 49 ' EPF 05-Jun-02 Unidades pendientes del movimiento en unidades no convertibles
    Public Const MOVTO_UNIDADESORIGEN = 50 ' RDAT 21-Jun-02 Movimiento Origen
    Public Const MOVTO_UNIDADESNCORIGEN = 51 ' RDAT 21-Jun-02 Movimiento Origen
    Public Const MOVTO_IMPORTEEXTRA1 = 58
    Public Const MOVTO_IMPORTEEXTRA2 = 59
    Public Const MOVTO_IMPORTEEXTRA3 = 60
    Public Const MOVTO_IMPORTEEXTRA4 = 61

    ' 20/03/2003 LAP SoluPAQ
    Public Const MOVTOS_SERIES = "MGW10036"     ' Tabla de movimiento de números de serie
    Public Const IxMOVTOS_SERIES = "PrimaryKey" ' Indice primario: cIdMovimiento + cIdSerie
    Public Const IxSERIESPRODUCTO = "INUMEROS01"      '
    Public Const MOVTOS_SERIES_IDMOVTO = 1
    Public Const MOVTOS_SERIES_IDSERIE = 2
    Public Const SERIES = "MGW10032"          ' Tabla de números de serie
    Public Const IxSERIES = "PrimaryKey"      ' Indice primario: cIdSerie
    Public Const SERIES_ESTADO = 5
    Public Const SERIES_LOTE = 7
    Public Const SERIES_CADUCIDAD = 8
    Public Const SERIES_FABRICACION = 9
    Public Const SERIES_PEDIMENTO = 10
    Public Const SERIES_ADUANA = 11
    Public Const SERIES_FECHA = 12
    Public Const kSerieDisponible = 1
    Public Const kSerieConsigProv = 2
    Public Const kSerieNoDisponible = 3
    Public Const kSerieHuerfana = 4
    Public Const kSerieHuerfanaConsig = 5
    Public Const kSerieInvFisico = 6
    Public Const kSerieVendida = 7
    Public Const kSerieConsigCliente = 8
    Public Const kSerieDevHuerfana = 9
    Public Const kSerieDevHuerfanaConsig = 10
    Public Const kSerieVendidaConsigProv = 11
    Public Const kSerieConsigCteConsigProv = 12

    Public Const MOVTOS_CAPAS = "MGW10028"     ' Tabla de movimiento de capas
    Public Const IxMOVTOS_CAPAS = "PrimaryKey" ' Indice primario: cIdMovimiento + cIdCapa
    Public Const MOVTOS_CAPAS_IDMOVTO = 1
    Public Const MOVTOS_CAPAS_IDCAPA = 2
    Public Const CAPAS = "MGW10025"          ' Tabla de capas
    Public Const IxCAPAS = "PrimaryKey"      ' Indice primario: cIdCapa
    Public Const CAPAS_LOTE = 6
    Public Const CAPAS_CADUCIDAD = 7
    Public Const CAPAS_FABRICACION = 8
    Public Const CAPAS_PEDIMENTO = 9
    Public Const CAPAS_ADUANA = 10
    Public Const CAPAS_FECHAPEDIMENTO = 11



    '**********************************************************
    'Variables del modulo
    '**********************************************************
    Public hDbc(30) As Long    'Conexion con la base de datos de Empresas
    Public HdbcEmp As Long     'Conexion con archivo de Empresas
    ' Variables para la empresa activa
    Public sEmpresaAct As String   ' Nombre de la empresa activa
    Public sDirectorioAct As String ' Directorio de la empresa activa, se inicializa
    'en GetEmpCurrPath, se modifica en GetParametros
    Public inumeroEmpresa As Integer
    Public gEmpActiva As Integer ' global, numero de la empresa activa
    Public Ruta_Xls As String              'Path del archivo XLS
    Public Dir_Emp As String               'Path de la empresa temporal
    Public Num_Emp, i As Integer           'Numero de empresas instaladas
    'Public Const szRegKeyAdminPAQ2001 = "SOFTWARE\Computación en Acción, SA CV\CONTPAQ I Comercial"
    Public Const szRegKeyAdminPAQ2001 = "SOFTWARE\Computación en Acción, SA CV\CONTPAQ I Comercial"
    Public Const szRegKeyAdminPAQ200164 = "SOFTWARE\Wow6432Node\Computación en Acción, SA CV\CONTPAQ I Comercial"
    Public Const szSistema = "AdminPAQ"     'F@C
    Public Const szRegKeySoluPAQ = "SOFTWARE\Computación en Acción, SA CV\Toma de Decisiones"
    'Public szDirectorioBase As String    ' Guarda la ruta del directorio de empresas, se inicializa
    ' en la función GetDirectorioBase, llamada desde el auto_open
    'Public Const URLSACI = "http://saci:9080/saci/adminpaq"

    'Public Property mstrsURLSACI As String
    'Public sUsuario As String
    'Public sPassword As String

    Public Const szRegKeyAdminPAQ = "SOFTWARE\Computación en Acción, SA CV\CONTPAQ I Comercial"
    Public Const szRegKeyAdminPAQ64 = "SOFTWARE\Wow6432Node\Computación en Acción, SA CV\CONTPAQ I Comercial"

    <DllImport("advapi32.DLL")> _
    Public Shared Function RegOpenKeyEx(ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
    End Function

    
End Class
